package cn.wj.school.cloud.dto;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * @Author: yueding
 * @Description: dubbo返回数据结构
 * @Date: Created in 10:22 2019/1/14
 * @Modified By: yueding Copyright(c) cai-inc.com
 */
@Data
public class Response<T> implements Serializable{
    private static final long serialVersionUID = -750644833749014618L;
    private boolean success;
    private T result;
    private String error;

    public static <T> Response<T> ok(T data) {
        Response resp = new Response();
        resp.setSuccess(Boolean.TRUE);
        resp.setResult(data);
        return resp;
    }

    public static <T> Response<T> ok() {
        return ok(null);
    }

    public static <T> Response<T> fail(String error) {
        Response resp = new Response();
        resp.setSuccess(Boolean.FALSE);
        resp.setError(error);
        return resp;
    }
}
